-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(guardrails): added guardrails block/tools and docs #1605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
Added comprehensive guardrails block with four validation types: JSON, Regex, Hallucination Check (RAG + LLM scoring), and PII Detection (Microsoft Presidio). Integrated with workflow blocks system, added new grouped checkbox UI component for PII type selection, updated Docker setup for Python dependencies, and included full documentation.
Key Changes:
- New guardrails block configuration with conditional UI based on validation type
- API route at
/api/guardrails/validatewith input validation and error handling - TypeScript validators for JSON, regex, and hallucination detection
- Python-based PII detection using Microsoft Presidio with TypeScript wrapper
- New
grouped-checkbox-listsub-block component for multi-select PII types - Docker configuration updated to install Python 3, pip, and run setup script
- Comprehensive documentation with examples and best practices
Critical Issue:
validate_pii.ts:82- Promise constructor missingrejectparameter, causing runtime errors on lines 100 and 178
Confidence Score: 2/5
- This PR has a critical bug that will cause runtime failures in PII validation
- Score reflects a critical logical error in
validate_pii.tswhere the Promise constructor is missing therejectparameter (line 82), butrejectis called on lines 100 and 178. This will cause immediate runtime errors when PII validation times out or encounters spawn errors. The rest of the implementation is well-structured with good error handling, comprehensive validation logic, and proper documentation. - Critical attention required for
apps/sim/lib/guardrails/validate_pii.ts- must fix Promise constructor before merge
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/guardrails/validate_pii.ts | 1/5 | PII validation with Python integration - critical bug: Promise missing reject parameter (lines 100, 178) |
| apps/sim/lib/guardrails/validate_hallucination.ts | 4/5 | Hallucination detection using RAG + LLM scoring - well-structured with proper error handling |
| apps/sim/blocks/blocks/guardrails.ts | 5/5 | Block configuration for guardrails with comprehensive PII types and conditional UI logic |
| apps/sim/app/api/guardrails/validate/route.ts | 5/5 | API route with input validation, type checking, and proper error handling |
| apps/sim/lib/guardrails/validate_pii.py | 5/5 | Python PII detection using Presidio with proper error handling and JSON output |
| docker/app.Dockerfile | 5/5 | Added Python 3 and pip to runner stage, copies guardrails setup files and runs setup script |
Sequence Diagram
sequenceDiagram
participant User
participant Block as Guardrails Block
participant Tool as guardrails_validate Tool
participant API as /api/guardrails/validate
participant Validator as Validation Logic
participant KB as Knowledge Base API
participant LLM as LLM Provider
participant Python as Python Script (PII)
User->>Block: Configure validation type & parameters
User->>Block: Wire input from previous block
Block->>Tool: Execute with input & config
Tool->>API: POST /api/guardrails/validate
alt JSON Validation
API->>Validator: validateJson(input)
Validator->>API: {passed, error?}
else Regex Validation
API->>Validator: validateRegex(input, pattern)
Validator->>API: {passed, error?}
else Hallucination Check
API->>Validator: validateHallucination(input, config)
Validator->>KB: Query knowledge base (RAG)
KB->>Validator: Return relevant chunks
Validator->>LLM: Score confidence (0-10)
LLM->>Validator: {score, reasoning}
Validator->>API: {passed, score, reasoning}
else PII Detection
API->>Validator: validatePII(input, config)
Validator->>Python: Spawn validate_pii.py
Python->>Python: Presidio analyze & anonymize
Python->>Validator: {passed, detectedEntities, maskedText?}
Validator->>API: {passed, detectedEntities, maskedText?}
end
API->>Tool: {success, output}
Tool->>Block: Return validation result
Block->>User: Display result (passed/failed)
25 files reviewed, 1 comment
8f82a12 to
62c07bc
Compare
* Adding guardrails block * ack PR comments * cleanup checkbox in dark mode * cleanup * fix supabase tools
* Adding guardrails block * ack PR comments * cleanup checkbox in dark mode * cleanup * fix supabase tools
* improvement(performance): remove unused source/target indices, add index on snapshot id (#1603) * fix(blog): rename building to blogs with redirect (#1604) * improvement(privacy-policy): updated privacy policy for google (#1602) * updated privacy policy for google * update terms, privacy, and emails to incl address and update verbiage * feat(guardrails): added guardrails block/tools and docs (#1605) * Adding guardrails block * ack PR comments * cleanup checkbox in dark mode * cleanup * fix supabase tools * fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (#1606) * fix(inference): fix inference billing when stream is true via API * add drag-and-drop to deployed chat * feat(mistal): added mistral as a provider, updated model prices (#1607) * feat(mistal): added mistral as a provider, updated model prices * remove the ability for a block to reference its own outluts * fixed order of responses for guardrails block * feat(versions): added the ability to rename deployment versions (#1610) * fix(vulns): fix various vulnerabilities and enhanced code security (#1611) * fix(vulns): fix SSRF vulnerabilities * cleanup * cleanup * regen docs * remove unused deps * fix failing tests * cleanup * update deps * regen bun lock
Summary
added guardrails block/tools and docs
Type of Change
Testing
Tested manually.
Checklist